﻿"use strict";
define(['admin/app', "service/admin/logisticsService"], function (app) {
    app.controller('logisticsController', function ($scope, $stateParams, $location, $uibModal, $state, utils, logisticsService) {
        $scope.query = {
            page: 1, size: 20, logistics_no: '', flight_no: '', postal_no: '',status: '', type: 2, 
        };
        $.extend($scope.query, $stateParams);
        var methods = {
            search: function () {
                logisticsService.gets($scope.query).success(function (response) {
                    $scope.model = response.data;
                });
            },
            get: function () {
                if ($stateParams.id > 0) {
                    logisticsService.get({ id: $stateParams.id }).success(function (response) {
                        $scope.model = response.data;
                    });
                    $scope.breadcrumb = '详情';
                }
            },
            get_logistics_status: function (type) {
                var logistics_status = new Array("备货", "提单", "分板", "运单航班", "空运航班抵达目的地", "身份信息匹配", "到库分栋，开始清关", "清关完成开始配送", "国内物流");
                return logistics_status[type - 1];
            },
            goBack: function () {
                history.back();
            },
            search_page: function (page) {
                $scope.query.page = page;
                methods.search('page', $scope.query.page);
            },
            push_order: function (id) {
                logisticsService.pushorder({ pay_id: id }).success(function (response) {
                    utils.notify(response, "success");
                });
            },
            push_pay_order: function (id) {
                logisticsService.pushpayorder({ pay_id: id }).success(function (response) {
                	utils.notify(response, "success");
                });
            },
            logistics_excel: function (id, type) {
                if(type == 1)
                $("#export"+id).attr("href", "/logistics/LogisticsExcel?logistics_id=" + id + "&type=" + type);
                else
                $("#exports"+id).attr("href", "/logistics/LogisticsExcel?logistics_id=" + id + "&type=" + type);
            },
            pay_type: function (types) {
                var pay_types = new Array("扫码支付", "快捷支付", "网关支付", "公众号/服务窗支付", "代付(通道结算到提现账号)", "SDK支付", "代收");
                return pay_types[types - 1];
            }
        }

        angular.extend($scope, methods);
        if ($state.includes('app.order.detail')) {
            methods.get();
        } else {
            methods.search();
        }
    });
});
